
/**
 * event type
 * START = 'start'
 * LOOP_COMPLETE = 'loopComplete'
 * COMPLETE='COMPLETE'
 * FADE_IN='fadeIn'
 * FADE_IN_COMPLETE='fadeInComplete'
 * FADE_OUT='fadeOut'
 * FADE_OUT_COMPLETE='fadeOutComplete'
 * FRAME_EVENT='frameEvent'
 * SOUND_EVENT='soundEvent'
 */
cc.Class({
    extends: cc.Component,

    properties: {
        armature : dragonBones.ArmatureDisplay
    },

    onLoad () {
        if(!this.armature){
            this.armature = this.node.getComponent(dragonBones.ArmatureDisplay)
        }
        if(!this.armature){
            console('没有指定动画模块:',this.node.name)
        }
        this.armature.addEventListener(dragonBones.EventObject.COMPLETE,this.onComplete,this)
        // cc.log('names:',this.armature.getArmatureNames())
    },

    onComplete(){
        // cc.log('播放完成:',arguments)
        this.animationIndex++;
        this.play();
    },

    play(){
        if(this.armature && this.animationNames.length > this.animationIndex){
            this.armature.playAnimation(this.animationNames[this.animationIndex]);
        } else {
            this.animationCB && this.animationCB();
        }
    },

    playDBArmature(names,cb){
        this.animationIndex = 0;
        this.animationNames = typeof names == 'object' ? names : [names];
        this.animationCB = cb;
        this.play();
    }
});
